﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// common 的摘要说明
/// </summary>
public class common
{
    public common()
    {
        
    }



    //将字符串进行编码格式转换，并进行MD5加密，然后返回
    public static string GetMD5(string dataStr, string codeType)
    {
        System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
        byte[] t = md5.ComputeHash(System.Text.Encoding.GetEncoding(codeType).GetBytes(dataStr));
        System.Text.StringBuilder sb = new System.Text.StringBuilder(32);
        for (int i = 0; i < t.Length; i++)
        {
            sb.Append(t[i].ToString("x").PadLeft(2, '0'));
        }
        return sb.ToString();
    }

    //将变量值不为空的参数组成字符串
    public static string appendParam(string returnStr, string paramId, string paramValue)
    {

        if (returnStr != "")
        {

            if (paramValue != "")
            {

                returnStr += "&" + paramId + "=" + paramValue;
            }

        }
        else
        {

            if (paramValue != "")
            {
                returnStr = paramId + "=" + paramValue;
            }
        }

        return returnStr;
    }

    public static DateTime StrToDateTime(string strDate)
    {
        strDate = strDate.Insert(4,"-");
        strDate = strDate.Insert(7, "-");
        strDate = strDate.Insert(10, " ");
        strDate = strDate.Insert(13, ":");
        strDate = strDate.Insert(16, ":");
        return DateTime.Parse(strDate);

    }
}
